import { constantRoutes, asyncRoutes } from '@/router'

const state = {
  routes: constantRoutes
}
const mutations = {
  setRoutes(state, otherRoutes) {
    state.routes = [...constantRoutes, ...otherRoutes]
  }
}
const actions = {
  // 封装一个筛选路由规则的action
  // 你得需要 所有动态路由们 , menus
  // 目标: 基于menus和asyncRoutes  去挑选属于他自己的路由规则
  // 分析: item.children[0].name
  filterRoutes(context, menus) {
    console.log('准备筛选路由了..', asyncRoutes, menus)
    const otherRoutes = asyncRoutes.filter(item => menus.includes(item.children[0].name))
    console.log('用户筛选得到的路由', otherRoutes)
    context.commit('setRoutes', otherRoutes)
    return otherRoutes
  }
}
const getters = {}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}
